
// 封装一个sessionStorage操作类
// 验证
function Verification(key,search) {
  this.key = key; // 用户名
  this.search = search; // 用户搜索记录
}
// 存储方法
Verification.prototype.setItem = function (type,item,data) {
  switch (type) {
    case 'sessionStorage':
      sessionStorage.setItem(item,data);
      break;
    case 'localStorage':
      localStorage.setItem(item,data);
      break;
  }
};
// 删除存储
Verification.prototype.removeItem = function (type,item) {
  switch (type) {
    case 'sessionStorage':
      sessionStorage.removeItem(item);
      break;
    case 'localStorage':
      localStorage.removeItem(item);
      break;
  }
};
// 登录
Verification.prototype.login = function (data) {
  this.setItem('localStorage',this.key,data)
};
// 退出登录
Verification.prototype.signOut = function () {
  this.removeItem('localStorage',this.key)
};
// 查询登录状态
Verification.prototype.query = function (key = this.key) {
  var res = localStorage.getItem(key);
  if (res) {
    return res;
  } else {
    return false;
  }
};
// 查询存储数据
Verification.prototype.getItem = function (type,key = this.search) {
  if (type == 0) {
    return sessionStorage.getItem(key);
  } else {
    return localStorage.getItem(key);
  }
};

// 导出实例
export default new Verification('user','search');

